/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：InventoryScreen.java <br>
 * 创建时间：2013-12-23 下午7:04:35 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.ui;

import com.orhanobut.logger.Logger;

import lostland.gmud.exv2.Gmud;
import lostland.gmud.exv2.MainCharTile;
import lostland.gmud.exv2.MapScreen;
import lostland.gmud.exv2.MapTile;
import lostland.gmud.exv2.blgframework.CScreen;
import lostland.gmud.exv2.data.Skill;
import lostland.gmud.exv2.ui.core.DoubleScrollScreen;
import lostland.gmud.exv2.ui.core.NewButton;

/**
 * 类名：SkillScreen <br>
 * 说明：技能界面
 *
 * @author 12548
 */
public class SkillScreen extends DoubleScrollScreen {

	AutoWindow bottomWindow;

	public SkillScreen(CScreen ts) {
		super(30, 30, 36, 222, 6);
		bottomWindow = new AutoWindow(x, y + max * 12, w1 + w2 - 1, 54, "");
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.DoubleScrollScreen#gets()
	 */
	@Override
	public void gets() {
		s1 = new String[]{"拳脚", "兵刃", "轻功", "内功", "招架", "知识"};

		if (s2 == null) {
			s2 = new String[6][];
		}

		if (__skill_sticking == null) {
			__skill_sticking = new int[10][Skill.getSkillCount()];
		}

		int i, k;
		for (i = 0; i < 6; i++) {
			if (i == 4) {
				continue;
			}

			k = 0;
			for (int j = 0; j < Gmud.mc.skills.length; j++)
				if (Gmud.mc.skills[j] > 0 && Gmud.skill[j].pos == i) {
					k++;
				}

			s2[i] = new String[k];

			k = 0;
			for (int j = 0; j < Gmud.mc.skills.length; j++) {
				if (Gmud.mc.skills[j] > 0 && Gmud.skill[j].pos == i) {

//					boolean b = false;
//					if(i<5)
//						if(GmudWorld.mc.skillsckd[i] == j)
//							b=true;

					s2[i][k] = Gmud.skill[j].name;
					__skill_sticking[i][k] = j;
					k++;
				}
			}
		}

		i = 4;

		k = 0;
		for (int j = 8; j < Gmud.mc.skills.length; j++)
			if (Gmud.mc.skills[j] > 0 && (Gmud.skill[j].pos == 0 || Gmud.skill[j].pos == 1 || Gmud.skill[j].pos == 4)) {
				k++;
			}

		s2[i] = new String[k];


		k = 0;
		for (int j = 8; j < Gmud.mc.skills.length; j++) {
			if (Gmud.mc.skills[j] > 0 && (Gmud.skill[j].pos == 0 || Gmud.skill[j].pos == 1 || Gmud.skill[j].pos == 4)) {

//				boolean b = false;
//				if(GmudWorld.mc.skillsckd[i] == j)
//					b=true;

				s2[i][k] = Gmud.skill[j].name;
				__skill_sticking[i][k] = j;
				k++;
			}
		}

	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.DoubleScrollScreen#onClick(int)
	 */
	@Override
	public void onClick(int cu) {
		int d = v1.cursor;
		int j = __skill_sticking[d][cu];
		Logger.i("group" + d + "child" + cu + "skill" + j);
		if (Gmud.skill[j].checkable && Gmud.skill[j].pos < 6) {
			if (Gmud.mc.skillsckd[d] == j) {
				Gmud.mc.skillsckd[d] = -1;
			} else {
				Gmud.mc.skillsckd[d] = j;
				if (d <= 1 && (Gmud.mc.skillsckd[4] < 42 || Gmud.mc.skillsckd[4] > 44)) {
					Gmud.mc.skillsckd[4] = j;
				}
			}

			Logger.i("checked skill:" + j + "on" + d);

		}

	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.DoubleScrollScreen#drawbg()
	 */
	@Override
	public void drawbg() {
		MapScreen.getInstance().getMap().draw(MapTile.getInstance(), MapScreen.X, MapScreen.Y);
		MainCharTile.getInstance().drawInMap(MainCharTile.getInstance().currentDirection,
				MainCharTile.getInstance().currentStep, MainCharTile.getInstance().X, MainCharTile.getInstance().Y);
		bottomWindow.draw();
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.DoubleScrollScreen#cancel()
	 */
	@Override
	public void cancel() {
//		game.setScreen(ts);
		getGame().popScreen();
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.DoubleScrollScreen#onButtonClick(lostland.gmud.exv2.ui.core.NewButton)
	 */
	@Override
	public void onButtonClick(NewButton b) {
		super.onButtonClick(b);
		if (layer == 1) {
			bottomWindow.text = "    " +
					Gmud.getLvlDesc(Gmud.mc.skills[__skill_sticking[v1.cursor][v2.cursor]] / 5) + "   " +
					Gmud.mc.skills[__skill_sticking[v1.cursor][v2.cursor]] + "/" +
					Gmud.mc.learning[__skill_sticking[v1.cursor][v2.cursor]] + "\n" +
					Gmud.skill[__skill_sticking[v1.cursor][v2.cursor]].des;
		} else {
			bottomWindow.text = "";
		}
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.DoubleScrollScreen#checkin()
	 */
	@Override
	public void checkin() {

		if (v1.cursor <= 4) {
			for (int i = 0; i < v2.buttons.length; i++) {
				v2.buttons[i].setChecked(Gmud.mc.skillsckd[v1.cursor] == __skill_sticking[v1.cursor][i]);
			}
		} else {
			for (int i = 0; i < v2.buttons.length; i++) {
				v2.buttons[i].setChecked(Gmud.mc.using(__skill_sticking[v1.cursor][i]));
			}
		}
	}

	protected boolean inBattle() {
		return __inventory_inbattle;
	}

	protected void setInbattle(boolean __inventory_inbattle) {
		this.__inventory_inbattle = __inventory_inbattle;
	}

}
